const http = require('../../../utils/http.js');
const app = getApp()
const utils = require('../../../utils/util.js')
Page({
  data: {
    status: false,
    searchValues: '请输入编号/手机号/姓名',
    hide: true,
    keyword: '',
    sercar: '全部用户',
    titleNum: '',
    group_total: 0,
    NetWorkStatus: true
  },
  onLoad: function (options) {
    var _this = this
    wx.getNetworkType({
      complete: (res) => {
        console.log(res)
        if (res.networkType == 'none') {
          _this.setData({
            NetWorkStatus: false
          })
        }
      },
    })
    _this.onFensiList()
  },
  onAgainLoadingTap() {
    var _this = this
    wx.showToast({
      title: '加载中',
      icon: 'loading'
    })
    wx.getNetworkType({
      complete: (res) => {
        console.log(res)
        if (res.networkType == 'none') {
          wx.hideToast()
          _this.setData({
            NetWorkStatus: false
          })
        }
      },
    })
    _this.onFensiList()
  },
  onReady: function () {},
  onShow: function () {},
  onHide: function () {},
  onUnload: function () {},
  onPullDownRefresh: function () {
    var _this = this
    _this.onFensiList()
  },
  onReachBottom: function () {},
  onShareAppMessage: function () {},
  onStatusClick() {
    var _this = this
    _this.setData({
      status: !_this.data.status
    })
  },
  keyword(e) {
    if (e.detail.value != '') {
      this.setData({
        hide: false
      })
    } else {
      this.setData({
        hide: true
      })
    }
  },
  Del() {
    this.setData({
      hide: false,
      searchValue: ''
    })
  },
  searchSubmitFn(e) {
    var _this = this,
      inputVal = e.detail.value
    _this.setData({
      keyword: inputVal
    })
    _this.onPageInfo(_this.data.group_id)

  },
  onFensiList() {
    // v1/fansGroup
    var _this = this
    wx.getNetworkType({
      complete: (res) => {
        console.log(res)
        if (res.networkType == 'none') {
          _this.setData({
            NetWorkStatus: false
          })
        }
      },
    })
    http.getRequest('v1/fansGroup', {},
      function (res) {
        console.log(res)
        wx.stopPullDownRefresh()
        wx.hideToast()
        _this.setData({
          listInfo: res.data,
          group_id: res.data[0].group_id,
          group_total: res.data[0].group_total,
          NetWorkStatus: true
        })
        _this.onPageInfo(0)
      },
      function (err) {
        console.log('》》网络加载失败了')
      })
  },
  onSearchListLi(e) {
    var _this = this
    _this.setData({
      sercar: e.currentTarget.dataset.name,
      status: false,
      group_total: e.currentTarget.dataset.group_total
    })
    _this.onPageInfo(e.currentTarget.id)
  },
  onPageInfo(e) {
    var _this = this
    wx.getNetworkType({
      complete: (res) => {
        console.log(res)
        if (res.networkType == 'none') {
          _this.setData({
            NetWorkStatus: false
          })
        }
      },
    })
    var data = {
      page: 0,
      group_id: e,
      keyword: _this.data.keyword
    }
    http.getRequest('v1/fansList', data,
      function (res) {
        if (res.data.list.length != 0) {
          for (let i in res.data.list) {
            res.data.list[i].create_time = utils.formatTime(res.data.list[i].create_time, 'Y-M-D h:m:s')
          }
        }
        _this.setData({
          userlist: res.data.list,
          NetWorkStatus: true
        })
      },
      function (err) {
        console.log('》》网络加载失败了')
      })
  }
})